<?php
declare (strict_types=1);

namespace app\common\listener;

use app\common\model\OrderProduct;
use app\common\model\Product;

class Operation
{
    public function handle($data)
    {
        $list = OrderProduct::where('order_id', $data)->field('pid,num')->select();

        foreach ($list as $v) {
            Product::where('id', $v->pid)->inc('sales', $v->num)->update();
            Product::where('id', $v->pid)->dec('stock', $v->num)->update();
        }
    }
}